unit untConstant;

interface

uses
  winapi.Windows, System.SysUtils, System.Classes;

const
  ERR_SC_SUCCESS = 0;
  ERR_SC_NOTACTIVE = 1;
  ERR_SC_BUSY = 2;
  ERR_SC_TIMEOUT = 3;
  ERR_DS_CHECKERR = 4;
  ERR_DS_FILENOTEEXIST = 5;
  ERR_DS_WRONGFILENO = 6;
  ERR_DS_DOWNFAILED = 7;
  ERR_DS_ISEMPTY = 8;
  ERR_DS_FAILED = 9;
  ERR_DS_BAD_FORMAT = 10;
  ERR_DS_WRONGFILENAME = 11;
  ERR_DS_UNKNOWNDEVICE = 12;

type
  TBaudRates = record
    BaudRateName: AnsiString;
    BaudRateNo: Integer;
  end;

const
  BaudRates: array[0..5] of TBaudRates = ((
    BaudRateName: '9600';
    BaudRateNo: 0
  ), (
    BaudRateName: '19200';
    BaudRateNo: 1
  ), (
    BaudRateName: '38400';
    BaudRateNo: 2
  ), (
    BaudRateName: '57600';
    BaudRateNo: 3
  ), (
    BaudRateName: '115200';
    BaudRateNo: 4
  ), (
    BaudRateName: '2400';
    BaudRateNo: 5
  ));

type
  TCommandModes = record
    CommandName: AnsiString;
    CommandNo: Integer;
  end;

const
  CommandModes: array[0..14] of TCommandModes = ((
    CommandName: 'LD220';
    CommandNo: 0
  ), (
    CommandName: 'EPSON Esc/POS';
    CommandNo: 1
  ), (
    CommandName: 'AEDEX';
    CommandNo: 2
  ), (
    CommandName: 'UTC/S';
    CommandNo: 3
  ), (
    CommandName: 'UTC/E';
    CommandNo: 4
  ), (
    CommandName: 'ADM788';
    CommandNo: 5
  ), (
    CommandName: 'DSP800';
    CommandNo: 6
  ), (
    CommandName: 'CD5220';
    CommandNo: 7
  ), (
    CommandName: 'EMAX';
    CommandNo: 8
  ), (
    CommandName: 'LOGIC CONTROL';
    CommandNo: 9
  ), (
    CommandName: 'ICD2002';
    CommandNo: 10
  ), (
    CommandName: 'EZ-202';
    CommandNo: 11
  ), (
    CommandName: 'PL-200';
    CommandNo: 12
  ), (
    CommandName: 'PD3000';
    CommandNo: 13
  ), (
    CommandName: 'AUTO';
    CommandNo: 255
  ));

type
  TCharsets = record
    DisplayNameEn: AnsiString;
    DisplayNameZh: AnsiString;
    CharsetNo: Integer;
  end;

const
  Charsets: array[0..12] of TCharsets = (
    (
    DisplayNameEn: 'USA';
    DisplayNameZh: '美国';
    CharsetNo: 0
  ), (
    DisplayNameEn: 'France';
    DisplayNameZh: '法国';
    CharsetNo: 1
  ), (
    DisplayNameEn: 'Germany';
    DisplayNameZh: '德国';
    CharsetNo: 2
  ), (
    DisplayNameEn: 'U.K.';
    DisplayNameZh: '英国';
    CharsetNo: 3
  ), (
    DisplayNameEn: 'Denmark I';
    DisplayNameZh: '丹麦I';
    CharsetNo: 4
  ), (
    DisplayNameEn: 'Sweden';
    DisplayNameZh: '瑞典';
    CharsetNo: 5
  ), (
    DisplayNameEn: 'Italy';
    DisplayNameZh: '意大利';
    CharsetNo: 6
  ), (
    DisplayNameEn: 'Spain';
    DisplayNameZh: '西班牙语系';
    CharsetNo: 7
  ), (
    DisplayNameEn: 'Japan';
    DisplayNameZh: '日本';
    CharsetNo: 8
  ), (
    DisplayNameEn: 'Norway';
    DisplayNameZh: '挪威';
    CharsetNo: 9
  ), (
    DisplayNameEn: 'Denmark II';
    DisplayNameZh: '丹麦II';
    CharsetNo: 10
  ), (
    DisplayNameEn: 'Slavonic';
    DisplayNameZh: '斯拉夫语系';
    CharsetNo: 11
  ), (
    DisplayNameEn: 'Russia';
    DisplayNameZh: '俄罗斯';
    CharsetNo: 12
  ));

type
  TCodePages = record
    DisplayName: string;
    CodePageName: Integer;
    CodePageNoOld: Integer;
    CodePageNoNew: Integer;
  end;

const
  CodePages: array[0..27] of TCodePages = (
    (
    DisplayName: 'CP437';
    CodePageName: 437;
    CodePageNoOld: 0;
    CodePageNoNew: 0
  ), (
    DisplayName: 'CP737';
    CodePageName: 737;
    CodePageNoOld: 17;
    CodePageNoNew: 21
  ), (
    DisplayName: 'CP737_S';
    CodePageName: 737;
    CodePageNoOld: 0;
    CodePageNoNew: 23
  ), (
    DisplayName: 'CP850';
    CodePageName: 850;
    CodePageNoOld: 2;
    CodePageNoNew: 2
  ), (
    DisplayName: 'CP852';
    CodePageName: 852;
    CodePageNoOld: 16;
    CodePageNoNew: 18
  ), (
    DisplayName: 'CP857';
    CodePageName: 857;
    CodePageNoOld: 9;
    CodePageNoNew: 9
  ), (
    DisplayName: 'CP858';
    CodePageName: 858;
    CodePageNoOld: 18;
    CodePageNoNew: 19
  ), (
    DisplayName: 'CP860';
    CodePageName: 860;
    CodePageNoOld: 3;
    CodePageNoNew: 3
  ), (
    DisplayName: 'CP863';
    CodePageName: 863;
    CodePageNoOld: 4;
    CodePageNoNew: 4
  ), (
    DisplayName: 'CP864';
    CodePageName: 864;
    CodePageNoOld: 19;
    CodePageNoNew: 22
  ), (
    DisplayName: 'CP865';
    CodePageName: 865;
    CodePageNoOld: 5;
    CodePageNoNew: 5
  ), (
    DisplayName: 'CP866';
    CodePageName: 866;
    CodePageNoOld: 15;
    CodePageNoNew: 17
  ), (
    DisplayName: 'CP866_AT';
    CodePageName: 866;
    CodePageNoOld: 0;
    CodePageNoNew: 15
  ), (
    DisplayName: 'CP874';
    CodePageName: 874;
    CodePageNoOld: 0;
    CodePageNoNew: 55
  ), (
    DisplayName: 'CP932';
    CodePageName: 932;
    CodePageNoOld: 1;
    CodePageNoNew: 1
  ), (
    DisplayName: 'CP936_GBK';
    CodePageName: 936;
    CodePageNoOld: 0;
    CodePageNoNew: 25
  ), (
    DisplayName: 'CP949';
    CodePageName: 949;
    CodePageNoOld: 0;
    CodePageNoNew: 129
  ), (
    DisplayName: 'CP950_BIG5';
    CodePageName: 950;
    CodePageNoOld: 0;
    CodePageNoNew: 146
  ), (
    DisplayName: 'WCP1250';
    CodePageName: 1250;
    CodePageNoOld: 11;
    CodePageNoNew: 11
  ), (
    DisplayName: 'WCP1251';
    CodePageName: 1251;
    CodePageNoOld: 14;
    CodePageNoNew: 14
  ), (
    DisplayName: 'WCP1252';
    CodePageName: 1252;
    CodePageNoOld: 8;
    CodePageNoNew: 16
  ), (
    DisplayName: 'WCP1253';
    CodePageName: 1253;
    CodePageNoOld: 12;
    CodePageNoNew: 47
  ), (
    DisplayName: 'WCP1254';
    CodePageName: 1254;
    CodePageNoOld: 0;
    CodePageNoNew: 50
  ), (
    DisplayName: 'WCP1255';
    CodePageName: 1255;
    CodePageNoOld: 13;
    CodePageNoNew: 49
  ), (
    DisplayName: 'WCP1256';
    CodePageName: 1256;
    CodePageNoOld: 0;
    CodePageNoNew: 24
  ), (
    DisplayName: 'WCP1257';
    CodePageName: 1257;
    CodePageNoOld: 21;
    CodePageNoNew: 51
  ), (
    DisplayName: 'WCP1257S';
    CodePageName: 1257;
    CodePageNoOld: 0;
    CodePageNoNew: 53
  ), (
    DisplayName: 'WCP1258';
    CodePageName: 1258;
    CodePageNoOld: 0;
    CodePageNoNew: 52
  ));

type
  TUploadFileInfo = record
    No: Integer;
    Caption: string;
    Name: string;
    Width: Integer;
    Height: Integer;
  end;

const
  UploadFileInfo_PD280_STYLE1: array[0..1] of TUploadFileInfo = (
    (
    Caption: 'Start_logo'; Name: 'logo.jpg'; Width: 240; Height: 320
  ), (
    Caption: 'Background'; Name: 'pl.jpg'; Width: 240; Height: 320
  ));

const
  UploadFileInfo_PD280_STYLE2: array[0..1] of TUploadFileInfo = (
    (
    Caption: 'Start_logo'; Name: 'logo.jpg'; Width: 240; Height: 320
  ), (
    Caption: 'QRCode_logo'; Name: 'cen.jpg'; Width: 60; Height: 60
  ));

const
  UploadFileInfo_PD280_STYLE3: array[0..10] of TUploadFileInfo = (
    (
    Caption: 'Picture1'; Name: 'sty3_P1.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture2'; Name: 'sty3_P2.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture3'; Name: 'sty3_P3.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture4'; Name: 'sty3_P4.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture5'; Name: 'sty3_P5.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture6'; Name: 'sty3_P6.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture7'; Name: 'sty3_P7.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture8'; Name: 'sty3_P8.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture9'; Name: 'sty3_P9.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Picture10'; Name: 'sty3_P10.jpg'; Width: 320; Height: 240
  ), (
    Caption: 'Start_logo'; Name: 'logo_sty3.jpg'; Width: 320; Height: 240
  ));

type
  TBarcodeType = record
    Value: Integer;
    Name: string;
  end;

const
  BarcodeTypes: array[0..87] of TBarcodeType = (
    (
    Value: 1; Name: 'Code 11'
  ),
    (
    Value: 2; Name: 'Standard Code 2 of 5'
  ),
    (
    Value: 3; Name: 'Interleaved 2 of 5'
  ),
    (
    Value: 4; Name: 'Code 2 of 5 IATA'
  ),
    (
    Value: 6; Name: 'Code 2 of 5 Data Logic'
  ),
    (
    Value: 7; Name: 'Code 2 of 5 Industrial'
  ),
    (
    Value: 8; Name: 'Code 3 of 9 (Code 39)'
  ),
    (
    Value: 9; Name: 'Extended Code 3 of 9 (Code 39+)'
  ),
    (
    Value: 13; Name: 'EAN (Including EAN-8 and EAN-13)'
  ),
    (
    Value: 14; Name: 'EAN + Check Digit'
  ),
    (
    Value: 16; Name: 'GS1-128 (UCC.EAN-128)'
  ),
    (
    Value: 18; Name: 'Codabar'
  ),
    (
    Value: 20; Name: 'Code 128 (automatic subset switching)'
  ),
    (
    Value: 21; Name: 'Deutshe Post Leitcode'
  ),
    (
    Value: 22; Name: 'Deutshe Post Identcode'
  ),
    (
    Value: 23; Name: 'Code 16K'
  ),
    (
    Value: 24; Name: 'Code 49'
  ),
    (
    Value: 25; Name: 'Code 93'
  ),
    (
    Value: 28; Name: 'Flattermarken'
  ),
    (
    Value: 29; Name: 'GS1 DataBar-14'
  ),
    (
    Value: 30; Name: 'GS1 DataBar Limited'
  ),
    (
    Value: 31; Name: 'GS1 DataBar Extended'
  ),
    (
    Value: 32; Name: 'Telepen Alpha'
  ),
    (
    Value: 34; Name: 'UPC A'
  ),
    (
    Value: 35; Name: 'UPC A + Check Digit'
  ),
    (
    Value: 37; Name: 'UPC E'
  ),
    (
    Value: 38; Name: 'UPC E + Check Digit'
  ),
    (
    Value: 40; Name: 'PostNet'
  ),
    (
    Value: 47; Name: 'MSI Plessey'
  ),
    (
    Value: 49; Name: 'FIM'
  ),
    (
    Value: 50; Name: 'LOGMARS'
  ),
    (
    Value: 51; Name: 'Pharmacode One-Track'
  ),
    (
    Value: 52; Name: 'PZN'
  ),
    (
    Value: 53; Name: 'Pharmacode Two-Track'
  ),
    (
    Value: 55; Name: 'PDF417'
  ),
    (
    Value: 56; Name: 'PDF417 Truncated'
  ),
    (
    Value: 57; Name: 'Maxicode'
  ),
    (
    Value: 58; Name: 'QR Code'
  ),
    (
    Value: 60; Name: 'Code 128 (Subset B)'
  ),
    (
    Value: 63; Name: 'Australia Post Standard Customer'
  ),
    (
    Value: 66; Name: 'Australia Post Reply Paid'
  ),
    (
    Value: 67; Name: 'Australia Post Routing'
  ),
    (
    Value: 68; Name: 'Australia Post Redirection'
  ),
    (
    Value: 69; Name: 'ISBN (EAN-13 with verification stage)'
  ),
    (
    Value: 70; Name: 'Royal Mail 4 State (RM4SCC)'
  ),
    (
    Value: 71; Name: 'Data Matrix (ECC200)'
  ),
    (
    Value: 72; Name: 'EAN-14'
  ),
    (
    Value: 74; Name: 'Codablock-F'
  ),
    (
    Value: 75; Name: 'NVE-18'
  ),
    (
    Value: 76; Name: 'Japanese Postal Code'
  ),
    (
    Value: 77; Name: 'Korea Post'
  ),
    (
    Value: 79; Name: 'GS1 DataBar-14 Stacked'
  ),
    (
    Value: 80; Name: 'GS1 DataBar-14 Stacked Omnidirectional'
  ),
    (
    Value: 81; Name: 'GS1 DataBar Expanded Stacked'
  ),
    (
    Value: 82; Name: 'PLANET'
  ),
    (
    Value: 84; Name: 'MicroPDF417'
  ),
    (
    Value: 85; Name: 'USPS OneCode'
  ),
    (
    Value: 86; Name: 'Plessey Code'
  ),
    (
    Value: 87; Name: 'Telepen Numeric'
  ),
    (
    Value: 89; Name: 'ITF-14'
  ),
    (
    Value: 90; Name: 'Dutch Post KIX Code'
  ),
    (
    Value: 92; Name: 'Aztec Code'
  ),
    (
    Value: 93; Name: 'DAFT Code'
  ),
    (
    Value: 97; Name: 'Micro QR Code'
  ),
    (
    Value: 98; Name: 'HIBC Code 128'
  ),
    (
    Value: 99; Name: 'HIBC Code 39'
  ),
    (
    Value: 102; Name: 'HIBC Data Matrix ECC200'
  ),
    (
    Value: 104; Name: 'HIBC QR Code'
  ),
    (
    Value: 106; Name: 'HIBC PDF417'
  ),
    (
    Value: 108; Name: 'HIBC MicroPDF417'
  ),
    (
    Value: 112; Name: 'HIBC Aztec Code'
  ),
    (
    Value: 115; Name: 'DotCode'
  ),
    (
    Value: 116; Name: 'Han Xin (Chinese Sensible) Code'
  ),
    (
    Value: 128; Name: 'Aztec Runes'
  ),
    (
    Value: 129; Name: 'Code 32'
  ),
    (
    Value: 130; Name: 'Composite Symbol with EAN linear component'
  ),
    (
    Value: 131; Name: 'Composite Symbol with GS1-128 linear component'
  ),
    (
    Value: 132; Name: 'Composite Symbol with GS1 DataBar-14 linear component'
  ),
    (
    Value: 133; Name: 'Composite Symbol with GS1 DataBar Limited component'
  ),
    (
    Value: 134; Name: 'Composite Symbol with GS1 DataBar Extended component'
  ),
    (
    Value: 135; Name: 'Composite Symbol with UPC A linear component'
  ),
    (
    Value: 136; Name: 'Composite Symbol with UPC E linear component'
  ),
    (
    Value: 137; Name: 'Composite Symbol with GS1 DataBar-14 Stacked component'
  ),
    (
    Value: 138; Name: 'Composite Symbol with GS1 DataBar-14 Stacked Omnidirectional component'
  ),
    (
    Value: 139; Name: 'Composite Symbol with GS1 DataBar Expanded Stacked component'
  ),
    (
    Value: 140; Name: 'Channel Code'
  ),
    (
    Value: 141; Name: 'Code One'
  ),
    (
    Value: 142; Name: 'Grid Matrix'
  ));

function ExplainError(iError: Integer): string;

function EnumComPorts(Ports: TStrings): boolean;

implementation

function ExplainError(iError: Integer): string;
begin
  case iError of
    ERR_SC_SUCCESS:
      Result := 'Success';
    ERR_SC_NOTACTIVE:
      Result := 'Serial port not opened';
    ERR_SC_BUSY:
      Result := 'Serial port is busy';
    ERR_SC_TIMEOUT:
      Result := 'Timeout';
    ERR_DS_CHECKERR:
      Result := 'Handshake failed';
    ERR_DS_FILENOTEEXIST:
      Result := 'File does not exist';
    ERR_DS_WRONGFILENO:
      Result := 'Wrong file number';
    ERR_DS_DOWNFAILED:
      Result := 'Download failed';
    ERR_DS_ISEMPTY:
      Result := 'Text is empty';
    ERR_DS_FAILED:
      Result := 'Execution failed';
    ERR_DS_BAD_FORMAT:
      Result := 'Bad file format';
    ERR_DS_WRONGFILENAME:
      Result := 'Wrong file name';
    ERR_DS_UNKNOWNDEVICE:
      Result := 'Unknown  device';
  else
    Result := 'Unknown error: ' + IntToStr(iError);
  end;
end;

function EnumComPorts(Ports: TStrings): boolean;
var
  KeyHandle: HKEY;
  ErrCode, Index: Integer;
  ValueName, Data: WideString;
  ValueLen, DataLen, ValueType: DWORD;
  TmpPorts: TStringList;
begin
  Result := False;

  ErrCode := RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'HARDWARE\DEVICEMAP\SERIALCOMM', 0, KEY_READ, KeyHandle);

  if ErrCode <> ERROR_SUCCESS then
    Exit;

  TmpPorts := TStringList.Create;
  try
    Index := 0;
    repeat
      ValueLen := 256;
      DataLen := 256;
      SetLength(ValueName, ValueLen);
      SetLength(Data, DataLen);
      ErrCode := RegEnumValue(KeyHandle, Index, PChar(ValueName),
        Cardinal(ValueLen), nil, @ValueType, PByte(PChar(Data)), @DataLen);

      if ErrCode = ERROR_SUCCESS then
      begin
        SetLength(Data, DataLen);
        TmpPorts.Add(Data);
        Inc(Index);
      end
      else if ErrCode <> ERROR_NO_MORE_ITEMS then
        Exit;
    until (ErrCode <> ERROR_SUCCESS);

    TmpPorts.Sort;
    Ports.Assign(TmpPorts);
    Result := True;
  finally
    RegCloseKey(KeyHandle);
    TmpPorts.Free;
  end;
end;

end.

